
#ifndef EXPRESSIONPARSER_HPP__
# define EXPRESSIONPARSER_HPP__

# include <map>
# include <string>

# include "Universe.hpp"
# include "ExpressionNode.hpp"

class ExpressionParser
{
public:
    ExpressionParser();
    virtual ~ExpressionParser();

public:
    bool getDataFromFile(std::string const & filename, Universe& universe);
    bool getResultFromFile(std::string const & filename, Universe& universe);
    std::pair<char, Tribool> peekFact(char const * stream);
    bool peekRule(char const * stream, Universe& universe);
    bool peekResult(char const * stream, Universe& universe);

private:
    ExpressionNode* _parseAntecedents(std::string const & s_antecedents, Universe& universe);
    ExpressionNode* _parseConclusion(std::string const & s_conclusion, Universe& universe);
    char _getValue(std::string const & expr);
    int _findOperatorMinPriority(std::string const & str);
    char const * _ignoreBlanks(char const * stream) const;
    bool _isBlank(char c) const;
    bool _isVariable(char c) const;
    bool _isOperator(char c) const;

private:
    std::map<char, int> _operatorPriority;
};

#endif // EXPRESSIONPARSER_HPP__
